package org.kzwl.service.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ServiceLogAspect {


    @Around("execution(* org.kzwl.service.app.impl..*.*(..))")
    public Object recordTimeLog(ProceedingJoinPoint joinPoint) throws Throwable {
        log.error("-------------- 开始执行 --------------");
         joinPoint.getTarget().getClass();
         String name = joinPoint.getSignature().getName();

        //开始时间
        long begin = System.currentTimeMillis();

        Object result = joinPoint.proceed();

        long end = System.currentTimeMillis();
        long takeTime = end - begin;

        log.error("方法名"+ name + "结果" + result);
        if (takeTime > 3000) {
            log.error("============ 执行结束, 耗时 {}毫秒 =============", takeTime);
        } else if (takeTime > 2000) {
            log.warn("======== =========执行结束, 耗时 {}毫秒===== ========", takeTime);
        } else {
            log.info("======== =======执行结束, 耗时 {}毫秒======== ========", takeTime);
        }

        return result;
    }
}
